﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CSharpDesign.DAL;
using CSharpDesign.Scripts;
using CSharpDesign.BLL;

namespace CSharpDesign.Admin
{
    public partial class tpnews_updt : System.Web.UI.Page
    {
        public string sql, dID;

        SqlHelper data = new SqlHelper();

        NewsService service = new NewsService();
        protected void Page_Load(object sender, EventArgs e)
        {
            dID = Request.QueryString["id"].ToString().Trim();
            if (!IsPostBack)
            {
                DropDownList1.DataSource = data.GetDataReader("select * from Infotype");
                DropDownList1.DataValueField = "id";
                DropDownList1.DataTextField = "name";
                DropDownList1.DataBind();
                sql = "select * from News where id=" + dID;
                getdata(sql);
            }
        }
        private void getdata(string sql)
        {
            SqlDataReader dr = data.GetDataReader(sql);
            if (dr.Read())
            {
                title.Text = dr["name"].ToString();
                content1.Value = dr["content"].ToString();
                DropDownList1.Items.FindByValue(dr["typeid"].ToString()).Selected = true;
                DropDownList1.Items.FindByText(dr["TypeName"].ToString()).Selected = true;
            }

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = title.Text.ToString().Trim();
            string content = content1.Value;
            string typeid = DropDownList1.SelectedValue;
            string TypeName = DropDownList1.SelectedItem.Text;
            service.UpdataNews(name, content, typeid, TypeName, dID);
            Alert.AlertAndRedirect("修改成功", "NewsList.aspx");
        }
    }

}